package com.ainge.easystudy.designpattern.singleton;

/**
 * 饿汉式单例
 * 优点：简单
 * 缺点：类加载的时候就初始化了，不管用与不用都站着内存空间
 *
 * @author: Ainge
 * @Time: 2021/4/24 15:00
 */
public class HungrySingleton {
    /**
     * 静态实例化
     */
    private static final HungrySingleton singleton = new HungrySingleton();

    private HungrySingleton(){
        if(singleton != null){
            throw new RuntimeException("防止反射实例化");
        }
    }
    public static HungrySingleton getInstance(){
        return singleton;
    }
}
